package services;

import dao.ArticleInfoDao;

import utils.ResultJSONUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:咭咭熊
 * Date:2021 - 08 - 03
 * Time:18:31
 */


@WebServlet("/mydel")//使用此注解标识当前servlet的路由
public class MyDelServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException {
        this.doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException {
        int succ = -1;//succ = 1表示操作成功
        String msg = "";//错误说明信息
        //1.得到前端传递的参数
        int id = Integer.parseInt(request.getParameter("id"));
        //2.调用数据库执行相应的业务逻辑
        ArticleInfoDao articleInfoDao = new ArticleInfoDao();
        //调用数据库进行文章删除
        succ = articleInfoDao.del(id);
        //3.返回结果
        HashMap<String,Object> ret = new HashMap<>();
        ret.put("succ",succ);
        ret.put("msg",msg);
        ResultJSONUtils.write(response,ret);

    }
}
